//
// Created by suzhen on 17-1-4.
//

#ifndef ORIONV2_HTTPRESPONSEBUILDER_H
#define ORIONV2_HTTPRESPONSEBUILDER_H

#include "Orion.h"
#include <sstream>

ORION_V2_NAMESPACE_BEGIN

        class HttpResponse {
        public:
            using HttpHeaderType =std::map<std::string, std::string>;

            HttpResponse(int httpCode,
                         const std::string &contentType,
                         const HttpHeaderType &headers = {});

            void setStatusCode(unsigned int code);

            void setContentType(const std::string &ctp);

            //append to body
            void writeBody(const std::string &bd);

            //append to header
            void writeHeader(const std::string &k, const std::string &v, bool forceOverride = YES);

            std::ostream &getOutPutStream();

            std::string buildHttpText();

        private:
            std::ostringstream body_{};
            int httpCode_{0};
            std::string contentType_;
            HttpHeaderType headers_{};
        };

ORION_V2_NAMESPACE_END


#endif //ORIONV2_HTTPRESPONSEBUILDER_H
